<template>
	<view class="container">
		<!-- <view class="loginsbox">
			<view class="wechatapp">
				<view class="header">
					<image class="image"
						src="@/static/default-avatar.png">
					</image>
				</view>
			</view>
			<view class="auth-title">申请获取以下权限</view>
			<view class="auth-subtitle">获得你的公开信息</view>
			<button type="primary"  @click.stop="login()">登录</button>
			<button type="primary" style="margin-top: 20rpx;"  @click.stop="onNavigateBack">取消登录</button>
		</view> -->
		
		<!-- 获取手机号 -->
		<!-- <view class="loginbox" v-if="mobileShow">
			<view class="logininfo">
				<view class="lohintitle">请先绑定手机号</view>
				<view class="loginbut">
					<view class="butone" @click="goback()">取消</view>
					<view class="buttwo">
						获取手机号
						<button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber"></button>
					</view>
				</view>
			</view>
		</view> -->
	</view>
</template>

<script>
	import {Login} from '../../uilt/h5Login.js'
	// import jweixin from '../../util/time.js'
	export default {
		data() {
			return {
				// 商城基本信息
				storeInfo: undefined,
				// 微信小程序登录凭证 (code)
				// 提交到后端，用于换取openid
				code:"",
				iv: "",
				userInfo:{},
				token:uni.getStorageSync('token'),
				userinfo:{},
			}
		},
		onShow() {
			// this.handleLogout()
			// this.load()
			if(this.token){
				window.location.href = 'http://nhcj.app65.cn/h5/#/';
			}else{
				
			}
		},
		onLoad(options) {
			uni.getNetworkType({
				success: function (res) {
					if(res.networkType === 'none') {
						uni.showToast({
							title: "您当前暂无网络，请检查网络连接",
							icon: "none"
						})
					}
				}
			});
			this.load()
		},
		methods: {
			load(){
				console.log('this.load')
				this.code = Login({
					appId:'wx6cfa9e1c68da9ea8',
					redirect_url:'http://nhcj.app65.cn/h5/#/pages/luck_draw/luck_draw'
				})
				console.log(this.code,'code')
				this.login()
			},
			// 退出登录
			   handleLogout() {
			   uni.clearStorage()
			   uni.reLaunch({
			    url: '/pages/index/index'
			   });
			   },
			login(){
				if(this.code){
					this.$http({
						url:'api/Wechat/wechat_register',
						data:{
							code:this.code,
							admin_id:uni.getStorageSync('admin_id'),
							p_road_id:uni.getStorageSync('ids')
						}
					}).then(res=>{
						console.log(this.token,res)
						uni.setStorageSync("token", res.data.openid);
						this.checkinfo()
						this.bindid()
						uni.setStorageSync('userInfo', res.data);
						setTimeout(()=>{
							console.log(this.token,res)
							// uni.redirectTo({
							// 	url:'/pages/index/index'
							// })
							window.location.href ='http://nhcj.app65.cn/h5/#/'
						},1000)
					})
				}
			},
			//绑定
			bindid(){
				this.$http({
					url:'api/answer/bind_admin',
					data:{
						admin_id:uni.getStorageSync('admin_id'),
						p_road_id:uni.getStorageSync('ids')||'',
						token:uni.getStorageSync('token')
					}
				}).then(res=>{
					
				})
			},
			checkinfo(){
				this.$http({
					url:'api/answer/update_qy',
					data:{
						token:uni.getStorageSync('token')
					}
				}).then(res=>{
					this.magstatus = false
				})
			},
			// 获取code
			onNavigateBack(delta = 1) {
				const pages = getCurrentPages()
				if (pages.length > 1) {
				  uni.navigateBack({
					delta: Number(delta || 1)
				  })
				} else {
					uni.redirectTo({
						url:'/pages/index/index'
					})
				}
			 },
			 //绑定手机号 mobile
			 getPhoneNumber(e){
			 	this.$http({
			 		url:'api/api/bind_mobile',
			 		data:{
			 			code:e.detail.code,
						token:uni.getStorageSync('token')
			 		}
			 	}).then(res=>{
					uni.showToast({
						title:res.msg,
						icon:'none'
					})
					this.mobileShow = false
					setTimeout(()=>{
							uni.redirectTo({
								url:'/pages/index/index'
							})
						},1000)
			 	})
			 },
			 goback(){
				 this.mobileShow = false
				uni.redirectTo({
					url:'/pages/index/index'
				})
			 }
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		// padding: 0 60rpx;
		font-size: 32rpx;
		background: #fff;
		min-height: 100vh;
	}
	.loginsbox{
		margin: 0 60rpx;
		.wechatapp {
			padding: 80rpx 0 48rpx;
			border-bottom: 1rpx solid #e3e3e3;
			margin-bottom: 72rpx;
			text-align: center;
		
			.header {
				width: 190rpx;
				height: 190rpx;
				border: 4rpx solid #fff;
				margin: 0 auto 0;
				border-radius: 50%;
				overflow: hidden;
				box-shadow: 2rpx 0 10rpx rgba(50, 50, 50, 0.3);
		
				.image {
					display: block;
					width: 100%;
					height: 100%;
				}
			}
		}
	}

	

	.auth-title {
		color: #585858;
		font-size: 34rpx;
		margin-bottom: 40rpx;
	}

	.auth-subtitle {
		color: #888;
		margin-bottom: 88rpx;
		font-size: 28rpx;
	}
	.loginbox {
		width: 100%;
		height: 100vh;
		background-color: rgba(0, 0, 0, 0.5);
		position: fixed;
		z-index: 99;
		top: 0;
		padding:0;
	
		// left: 0rpx;
		.logininfo {
			// position: fixed;
			width: 560rpx;
			margin: auto;
			height: 289rpx;
			background-color: #ffffff;
			padding: 60rpx 50rpx 40rpx 50rpx;
			margin-top: 552rpx;
			border-radius: 20rpx;
	
			.lohintitle {
				width: 360rpx;
				font-size: 36rpx;
				font-family: Source Han Sans CN;
				font-weight: 500;
				color: #222222;
				margin: auto;
				margin-bottom: 60rpx;
				text-align: center;
			}
	
			.loginbut {
				display: flex;
				justify-content: space-between;
	
				.butone {
					width: 190rpx;
					height: 86rpx;
					line-height: 86rpx;
					text-align: center;
					border: 2rpx solid #5194FB;
					border-radius: 43rpx;
					font-size: 34rpx;
					font-family: Source Han Sans CN;
					font-weight: 400;
					color: #5194FB;
				}
	
				.buttwo {
					position: relative;
					width: 190rpx;
					height: 86rpx;
					line-height: 86rpx;
					text-align: center;
					background: linear-gradient(180deg, #5194FB 0%, #823DF6 100%);
					border-radius: 43rpx;
					font-size: 34rpx;
					font-family: Source Han Sans CN;
					font-weight: 400;
					color: #fff;
	
					>button {
						position: absolute;
						opacity: 0;
						left: 0;
						top: 0;
						width: 100%;
						height: 100%;
					}
				}
			}
		}
	}
</style>
